package powerdev.servlet;

import java.io.IOException;
import java.sql.Date;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import powerdev.excepcion.DAOExcepcion;
import powerdev.modelo.Evento;
import powerdev.negocio.GestionEvento;

/**
 * Servlet implementation class RegistrarEvento
 */
@WebServlet("/RegistrarEvento")
public class RegistrarEvento extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegistrarEvento() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		Evento lc = new Evento();
		GestionEvento neg=new GestionEvento();
		
		String a=request.getParameter("txtEvento");
		String b=request.getParameter("txtPremio");
		//String b=request.getParameter("txtCantidadLimite");
		Integer c=Integer.parseInt(request.getParameter("txtCantidadLimite"));
		//Date d=request.getParameter("txtPlazoInscripcion");
		Date d = Date.valueOf(request.getParameter("txtPlazoInscripcion"));
		
		
		
		try {
			neg.insertarEvento(b, a, c, d, true, 2);
			
			request.setAttribute("MENSAJE", "Se registro correctamente el evento.");
			
		} catch (DAOExcepcion e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			request.setAttribute("MENSAJE", e1.getMessage());
		}

		RequestDispatcher rd = request
				.getRequestDispatcher("powerdev_evento_insertar.jsp");
		rd.forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
